home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2783 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What should be returned?
  5. Date: Tue, 23 Jan 1996 22:11:19 GMT
  6. Organization: Netcom
  7. Message-ID: <310551bb.169614464@nntp.ix.netcom.com>
  8. References: <4dj8pv$cjd@eng_ser1.erg.cuhk.hk> <30fd5c1a.5495936@nntp.ix.netcom.com> <4dnf7d$1sa@fountain.mindlink.net>
  9. NNTP-Posting-Host: ix-dc18-03.ix.netcom.com
  10. X-NETCOM-Date: Tue Jan 23  2:10:38 PM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. genew@mindlink.bc.ca (Gene Wirchenko) wrote:
  14.  
  15. > miker3@ix.netcom.com (Mike Rubenstein) wrote:
  16. > >In fact, it's even legal to have neither a return or exit():
  17. > >    int main(void)
  18. > >    {
  19. > >    }
  20. > >This will return an undefined value to the operating environment, but
  21. > >does not result in undefined behavior and will not do damage.  I
  22. >      Returning an undefined value doesn't result in undefined
  23. > bahavior?  You been smokin' sumthin' funny, boy?
  24. >      What happens if/when the return value is interrogated as in
  25. > MS-DOS's ERRORLEVEL or <other OS>'s <appropriate feature>?
  26.  
  27. I've not been smoking anything -- I've just been reading the standard
  28. in which returning an undefined value does not result in undefined
  29. behavior.  First, there is no requirement in the standard that the
  30. operating system or shell use the returned value.  
  31.  
  32. Furthermore, the standard does not define what the operating system
  33. does with any value, including 0, EXIT_SUCCESS, or EXIT_FAILURE simply
  34. because that is beyond the scope of the standard.
  35.  
  36. The standard is very clear (ISO 5.1.2.2.3):
  37.  
  38.     If the main function executes a return that specifies no 
  39.     value, the termination status to the host environment is 
  40.     undefined.
  41.  
  42. It does not say the behavior is undefined, it does not say that the
  43. main function shall return a value, and it does not leave undefined
  44. the effect of returning no value.  These are the only ways the
  45. stadnard indicates undefined behavior (ISO 3.17), so returning no
  46. value does not result in undefined value.
  47.  
  48.  
  49. Michael M Rubenstein
  50.